import { createMemoryHistory, createRouter } from "vue-router";
import HomePage from "../pages/Home.vue"
import LoginPage from "../pages/Login.vue"
import { useUserStore } from "../stores/userStore";
const routes = [
    { path: '/', name: 'home', component: HomePage },
    { path: '/Login', name: 'login', component: LoginPage },
]

export const router = createRouter({
    history: createMemoryHistory(),
    routes,
})
router.beforeEach(async (to, _from) => {
    const userStore = useUserStore();
    if (userStore.getUserId === 0 && to.name !== 'login') {
        return { name: 'login' }
    }
})